#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;

void test(){
    vector<int> numbers({1, 2, 3, 4, 4, 6, 8, 9});
    cout << sizeof(numbers) << endl;
    //遍历的方式
    //方式1：使用下标访问来进行遍历
    for(size_t i = 0; i < numbers.size(); ++i){
        cout << numbers[i] << endl;
    }
    cout << "=============" << endl;
    //方式2：使用增强for循环来进行处理
    for(auto & ele : numbers){
        cout << ele << endl;
    }
    cout << "===========" << endl;
    //方式3：使用迭代器来进行遍历
    auto it = numbers.begin();
    while(it != numbers.end()){
        cout << *it << endl;
        ++it;
    }
}

class Point{
public:
    Point(int x, int y)
    :_x(x)
    ,_y(y)
    {
        cout << "Point(int,int)" << endl;
    }

    Point(const Point & rhs)
    :_x(rhs._x)
    ,_y(rhs._y)
    {
        cout << "Point(const Point &)" << endl;
    }

private:
    int _x;
    int _y;
};

void test2(){
    vector<Point> vec;
    vec.reserve(20);
    vec.push_back(Point(1, 2));
    cout << vec.size() << ":::::" << vec.capacity() << endl;
    vec.push_back(Point(3, 4));
    cout << vec.size() << ":::::" << vec.capacity() << endl;
    vec.push_back(Point(5, 6));
    cout << vec.size() << ":::::" << vec.capacity() << endl;
    vec.push_back(Point(7, 2));
    cout << vec.size() << ":::::" << vec.capacity() << endl;
    vec.push_back(Point(9, 10));
    cout << vec.size() << ":::::" << vec.capacity() << endl;
}

void test3(){
    vector<Point> vec;
    cout << sizeof(vec) << endl;
    vec.reserve(20);
    //该函数的使用和push_back有比较大的区别
    //只需要提供构造函数的参数即可
    //vector会在所属的内存区域中直接帮助我们调用构造函数
    //来完成对象的构造，避免了对象的拷贝过程
    vec.emplace_back(1, 2);
    cout << vec.size() << ":::::" << vec.capacity() << endl;
    vec.emplace_back(3, 4);
    cout << vec.size() << ":::::" << vec.capacity() << endl;
    vec.emplace_back(5, 6);
    cout << vec.size() << ":::::" << vec.capacity() << endl;
    vec.emplace_back(7, 8);
    cout << vec.size() << ":::::" << vec.capacity() << endl;
    vec.emplace_back(9, 10);
    cout << vec.size() << ":::::" << vec.capacity() << endl;

    cout << sizeof(vec) << endl;
}

int main()
{
    test();
    return 0;
}

